Skip to content

Conversation

@aduth
Copy link
Member

@aduth aduth commented May 1, 2018

This pull request seeks to bring in React's (new as of 16.3.0) forwardRef as an alternative solution for components which need to expose its internal DOM representation. A Button abstraction is a perfect use case for this, where we expose an instance function focus to recreate the native DOM behavior. Instead, we can simply forward the ref so that any parent component which assigns a ref to Button will have its value assigned as the actual DOM node.

Testing instructions:

Verify that there are no regressions in the behavior of button, particularly in the two places where its ref is used for focus: Permalinks returning focus after pressing "OK" on an edit, and similarly for Shared Blocks pressing "OK" on an edit, returning focus to the permalink and Edit buttons respectively.

@aduth aduth added Framework Issues related to broader framework topics, especially as it relates to javascript [Feature] UI Components Impacts or related to the UI component system labels May 1, 2018
Copy link
Member

@noisysocks noisysocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this.

If memory serves me, PostPermalink was the only component using focus(). I tested editing post permalinks and there are no regressions.

👍 once Travis CI is happy.

// Disable reason: This test is desirable, but unsupported by Enzyme in
// the current version, as it depends on features new to React in 16.3.0.
//
// eslint-disable-next-line jest/no-disabled-tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we e.g. create an issue to remind us to unskip this in the future?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we e.g. create an issue to remind us to unskip this in the future?

Created at #7005

@aduth
Copy link
Member Author

aduth commented May 4, 2018

Hmm, unfortunately seems to be another instance of Enzyme lagging behind React: enzymejs/enzyme#1604

Was able to implement the workaround for the buttons tests themselves, but will have to see what I can do for other components which render buttons (failing Autocomplete tests, for example).

@aduth aduth force-pushed the add/forward-ref branch from 77733a8 to cc04074 Compare May 4, 2018 13:56
@aduth
Copy link
Member Author

aduth commented May 4, 2018

While not the most beautiful thing, I was able to work around the issue by adding a global mock for Button to effectively unwrap the forwardRef. I'll plan to create a task to revisit both this and the skipped test.

cc @xyfi who I see encountered similar issues in #6261 with forwardRef.

@noisysocks noisysocks merged commit 0bdcdfa into master May 8, 2018
@noisysocks noisysocks deleted the add/forward-ref branch May 8, 2018 06:01
@gziolo
Copy link
Member

gziolo commented May 29, 2018

Hmm, unfortunately seems to be another instance of Enzyme lagging behind React: enzymejs/enzyme#1604

yes, this is pretty sad that they failed to upgrade to React 16.3 :(


mount( <ButtonWithForwardedRef ref={ ref } /> );

expect( ref.current.nodeName ).toBe( 'button' );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will fail when unskipped: Element#nodeName returns uppercase, so should be asserting as toBe( 'BUTTON' );

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may take another few weeks until we can unskip those tests :(
The day when we remove Enzyme is becoming a reality if there is no progress on supporting React 16.3+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] UI Components Impacts or related to the UI component system Framework Issues related to broader framework topics, especially as it relates to javascript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants